package o.gwtp.editor.client.editor;

import o.gwtp.editor.client.editor.EditorPresenter.EditorProxy;
import o.gwtp.editor.client.editor.EditorPresenter.EditorView;

import com.google.inject.Inject;
import com.google.inject.Provider;
import com.gwtplatform.mvp.client.EventBus;

/**
 * @author Olivier Monaco
 */
public class EditorPresenterProvider implements Provider<EditorPresenter> {
  private EditorPresenter presenter;
  private EventBus eventBus;
  private Provider<EditorView> view;
  private EditorProxy proxy;
  private String name;

  @Inject
  public EditorPresenterProvider(EventBus eventBus, Provider<EditorView> view) {
    this.eventBus = eventBus;
    this.view = view;
  }

  @Override
  public EditorPresenter get() {
    assert proxy != null : "You must call setProxy first";
    if (presenter == null) {
      presenter = new EditorPresenter(eventBus, view.get(), proxy, name);
    }
    return presenter;
  }

  public void setName(String name) {
    this.name = name;
  }

  public void setProxy(EditorProxy proxy) {
    this.proxy = proxy;
  }
}
